<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    const delay = (ms) =>
      new Promise((resolve) => {
        setTimeout(resolve, ms);
      });

    const Authorization = () => window.localStorage.getItem("token") ?? '';

    const waitForAuthorization = async () => {
      await delay(100);
      if (Authorization()) {
        return true;
      }
      await waitForAuthorization();
    };

    setTimeout(() => {
      window.localStorage.setItem("token", '1')
    }, 5000);
    const run = async () => {
      await waitForAuthorization();
      console.log('authorized');
    }
    run()
  </script>
</body>

</html>